import React from 'react'
import {Table} from 'antd'
import  "./index.less"
export default class ETable extends React.Component {

    state = {
        selectedRowKeys: [] // 选择行的id数组
    };

    onSelectChange = (selectedRowKeys, selectedRows) => {
        console.log('selectedRowKeys changed: ', selectedRowKeys, selectedRows);
        this.setState({ selectedRowKeys,selectedRows });
    }

    render() {
        const { selectedRowKeys } = this.state;

        let rowSelection
        if (this.props.rowSelection) { // 使用表格复选框
            rowSelection = {
                type: null,
                selectedRowKeys,
                onChange: this.onSelectChange,
            };
        } else { // 不启用表格复选框
            rowSelection = null
        }
        return (
            <div>
                <Table
                    rowSelection={rowSelection||null}
                    columns={this.props.columns}
                    dataSource={this.props.dataSource}
                    pagination={this.props.pagination}
                />
            </div>
        );
    }
}